﻿@model ProfileIM
@{
    ViewBag.Title = "个人资料";
}

@section header{
    <link href="~/plugins/webuploader/webuploader.min.css" rel="stylesheet" />

    
    }

<div class="container">
    <div class="row">
        <aside class="col-sm-3">
            @Html.Partial("_AccountNav")
        </aside>
        <section class="col-sm-9">

            @using (Ajax.BeginForm("MyProfile", "Account",
                    new AjaxOptions()
                    {
                        HttpMethod = "POST",
                        OnBegin = "onBeginSave",
                        OnComplete = "onCompleteSave",
                        OnSuccess = "updateSuccess",
                        //OnFailure = "handleError",
                        //  UpdateTargetId = "RoleList"

                    }, new { @class = "form-horizontal", role = "form" }))
            {
                @Html.AntiForgeryToken()
                @Html.ValidationSummary(true)
                @Html.HiddenFor(model => model.Id)


                <div class="panel panel-default">
                    <div class="panel-heading">
                        <h3 class="panel-title">编辑资料</h3>
                    </div>
                    <div class="panel-body">

                        <div class="row">
                            <div class="col-sm-4 col-sm-offset-4">
                                <div class="thumbnail">
                                    <img src="@ViewData["PhotoUrl"]" alt="头像" id="userPhoto">
                                    <div class="caption">                                       
                                        @*<p class="text-center">
                                            <a href="#" class="btn btn-primary" role="button">编辑</a>                                       
                                        </p>*@
                                        <!--dom结构部分-->
                                        <div id="uploader-demo">
                                            <!--用来存放item-->
                                            <div id="fileList" class="uploader-list"></div>
                                            <div id="filePicker">选择图片</div>
                                        </div>
                                     
                                    </div>
                                </div>
                            </div>
                        </div>
                      
                        <div class="form-group">
                            @Html.LabelFor(model => model.UserName, htmlAttributes: new { @class = "control-label col-md-3" })
                            <div class="col-md-9">
                                <p class="form-control-static">
                                    @Html.DisplayFor(model => model.UserName)
                                </p>
                            </div>
                        </div>


                        <div class="form-group">
                            @Html.LabelFor(model => model.Email, htmlAttributes: new { @class = "control-label col-md-3" })
                            <div class="col-md-9">
                                @Html.EditorFor(model => model.Email, new { htmlAttributes = new { @class = "form-control" } })
                                @Html.ValidationMessageFor(model => model.Email)
                            </div>
                        </div>



                        <div class="form-group">
                            @Html.LabelFor(model => model.RealName, htmlAttributes: new { @class = "control-label col-md-3" })
                            <div class="col-md-9">
                                @Html.EditorFor(model => model.RealName, new { htmlAttributes = new { @class = "form-control" } })
                                @Html.ValidationMessageFor(model => model.RealName)
                            </div>
                        </div>
                        <div class="form-group">
                            @Html.LabelFor(model => model.Birthday, htmlAttributes: new { @class = "control-label col-md-3" })
                            <div class="col-md-9">

                                @Html.EditorFor(model => model.Birthday, new { htmlAttributes = new { @class = "form-control" } })
                                @Html.ValidationMessageFor(model => model.Birthday)
                            </div>
                        </div>

                        <div class="form-group">
                            @Html.LabelFor(model => model.Gender, htmlAttributes: new { @class = "control-label col-md-3" })
                            <div class="col-md-9">
                                @Html.EnumDropDownListFor(model => model.Gender, htmlAttributes: new { @class = "form-control" })
                                @Html.ValidationMessageFor(model => model.Gender)
                            </div>
                        </div>

                        <div class="form-group">
                            @Html.LabelFor(model => model.Mobile, htmlAttributes: new { @class = "control-label col-md-3" })
                            <div class="col-md-9">
                                @Html.EditorFor(model => model.Mobile, new { htmlAttributes = new { @class = "form-control" } })
                                @Html.ValidationMessageFor(model => model.Mobile)
                            </div>
                        </div>

                        <div class="form-group">
                            @Html.LabelFor(model => model.QQ, htmlAttributes: new { @class = "control-label col-md-3" })
                            <div class="col-md-9">
                                @Html.EditorFor(model => model.QQ, new { htmlAttributes = new { @class = "form-control" } })
                                @Html.ValidationMessageFor(model => model.QQ)
                            </div>
                        </div>


                        <div class="form-group">
                            @Html.LabelFor(model => model.IsActive, htmlAttributes: new { @class = "control-label col-md-3" })
                            <div class="col-md-9">
                                <div class="checkbox">
                                    <label>
                                        @Html.EditorFor(model => model.IsActive)
                                        @Html.ValidationMessageFor(model => model.IsActive)
                                    </label>
                                </div>
                            </div>
                        </div>

                    </div>
                    <div class="panel-footer text-center">
                     
                        <button class="btn btn-primary" type="submit" id="btnSave"><i class="fa fa-save fa-fw"></i>保存</button>
                        <button type="reset" class="btn btn-default">重设</button>
                    </div>
                </div>

            }


        </section>
    </div>
</div>

@section Footer {
    @Scripts.Render("~/bundles/jqueryvalWithBootstrap")
<script src="~/plugins/webuploader/webuploader.min.js"></script>
<script>

    // 初始化Web Uploader
    var uploader = WebUploader.create({
        // 选完文件后，是否自动上传。
        auto: true,
       
        // swf文件路径
        swf: '/plugins/webuploader/Uploader.swf',

        // 文件接收服务端。
        server: '@Url.Action("UpLoadProcess")',

        // 选择文件的按钮。可选。
        // 内部根据当前运行是创建，可能是input元素，也可能是flash.
        pick: { id: '#filePicker', multiple: false, innerHTML:'上传头像' },

        // 只允许选择图片文件。
        accept: {
            title: 'Images',
            extensions: 'gif,jpg,jpeg,bmp,png',
            mimeTypes: 'image/*'
        }
    });
        
    // 文件上传成功，给item添加成功class, 用样式标记上传成功。
    uploader.on('uploadSuccess', function (file, response) {     
        $("#userPhoto").attr("src", response.filePath);    
    });

    // 文件上传失败，显示上传出错。
    uploader.on('uploadError', function (file) {       
        toastr.error("上传失败", "上传头像")       
    });

   


    //----------------------------------------------------------------------------------------------

    $.validator.addMethod('qq', function (value, element) {
        if (value.length > 0)
            return /^[1-9][0-9]{4,9}$/.test(value)
        return true;
    });
    $.validator.unobtrusive.adapters.addBool("qq");

    $.validator.addMethod('chinamobile', function (value, element) {
        if (value.length > 0)
            return /^0{0,1}(13[0-9]|15[7-9]|153|156|170|178|18[0-9])[0-9]{8}$/.test(value)
        return true;
    });

    $.validator.unobtrusive.adapters.addBool("chinamobile");


    function onBeginSave() {
        $("#btnSave i").removeClass("fa-save").addClass("fa-spinner fa-spin");
    }
    function onCompleteSave() {
        $("#btnSave i").removeClass("fa-spinner fa-spin").addClass("fa-save");
    }

    function updateSuccess(data) {
        var title = '@ViewBag.Title';
        Common.ShowBox(data.Status, data.Message, title);
    }

        $(function () {

        })
</script>
}



    }